package Week6.J0525;
// dfs?

import java.util.Scanner;

public class abb_xv {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        char[] s = scanner.next().toCharArray();
        long[] f = new long[26];
        long[] g = new long[26];
        long ret = 0;

        for (int i = 0; i < n; i++) {
            int x = s[i] - 'a';
            ret += f[x];

            f[x] = f[x] + i - g[x];
            g[x] = g[x] + 1;
        }
        System.out.println(ret);
    }
}
